//
//  PopAnimation.m
//  UI29-TableVIew(TranistionAnimation)
//
//  Created by 韩旭 on 16/8/23.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "PopAnimation.h"
#import "ViewController.h"
#import "DetailViewController.h"
#import "Hx_TableViewCustom.h"
@implementation PopAnimation

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
    return 0.5;
}

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
    DetailViewController *detail = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    ViewController *first = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *cotainView = [transitionContext containerView];
    [cotainView addSubview:first.view];
    [cotainView addSubview:detail.lableDetail];
    detail.imageView.hidden = YES;
    UIView *snapView = [first.customCell.ImageForm snapshotViewAfterScreenUpdates:NO];
    snapView.frame = detail.imageView.frame;
    [cotainView addSubview:snapView];
    [UIView animateWithDuration:1 animations:^{
        [cotainView layoutIfNeeded];
        snapView.frame = first.newRect;
    }completion:^(BOOL finished) {
        [snapView removeFromSuperview];
        [transitionContext completeTransition:YES];
    }];
}
@end
